package testng.service;

import java.util.List;

import com.iwhalecloud.citybrain.flow.platform.manager.FlowEngineApplication;
import com.iwhalecloud.citybrain.flow.platform.manager.common.FouraUser;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.FlowUser;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.model.User;
import com.iwhalecloud.citybrain.flow.platform.manager.domain.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.Assert;

/**
 * @author cheng.huaxing
 * @date 2019-02-25
 */
@SpringBootTest(classes = FlowEngineApplication.class)
public class UserServiceImplTest extends AbstractTransactionalTestNGSpringContextTests {

    @Autowired
    private UserRepository userRepository;

    //@Test
    public void testGetCurrentUser() {
        User user = userRepository.getCurrentUser();
        Assert.assertNotNull(user.getId());
    }

    //@Test
    public void testGetUserById() {
        User user = userRepository.getUserById("13580447986");
        Assert.assertNotNull(user.getId());
    }

    //@Test
    public void testGetUserByName() {
        User user = userRepository.getUserByName("成华星");
        Assert.assertNotNull(user.getId());
    }

    //@Test
    public void  testGetUserByCode() {
        User user = userRepository.getUserByCode("13580447986");
        Assert.assertNotNull(user.getId());
    }

    //@Test
    public void testInsertFlowUser() {
        FlowUser userInfo = new FlowUser();
        userInfo.setUserId("test001");
        userInfo.setUserCode("test001");
        userInfo.setUserName("test001");
        userInfo.setUserType("NORMAL");
        Assert.assertNotNull(userRepository.insertFlowUser(userInfo));
    }

    //@Test
    public void testInsertFouraUser() {
        FouraUser userInfo = new FouraUser("test001", "test001", "test001");
        Assert.assertNotNull(userRepository.insertFouraUser(userInfo));
    }

    //@Test
    public void testListAppAuthorizedUser() {
        List<FlowUser> list = userRepository.listAppAuthorizedUser(10);
        Assert.assertFalse(list.isEmpty());
    }

    //@Test
    public void testUpdateFlowUser() {
        FlowUser userInfo = new FlowUser();
        userInfo.setId(6);
        userInfo.setUserId("test001");
        userInfo.setUserCode("test001");
        userInfo.setUserName("test001");
        userInfo.setUserType("NORMAL");
        Assert.assertNotNull(userRepository.updateFlowUser(userInfo));
    }

}